<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="110px">
      <el-form-item label="学生id" prop="studentId">
        <el-input
          v-model="queryParams.studentId"
          placeholder="请输入学生id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="初次报到时间" prop="firstInternshipDate">
        <el-date-picker
          v-model="queryParams.firstInternshipDate"
          clearable
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择初次报到时间"
        />
      </el-form-item>
      <el-form-item label="初次报到单位" prop="firstInternshipCompany">
        <el-input
          v-model="queryParams.firstInternshipCompany"
          placeholder="请输入初次报到单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="有无变动1" prop="moveOne">
        <el-input
          v-model="queryParams.moveOne"
          placeholder="请输入有无变动1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="有无变动2" prop="moveTwo">
        <el-input
          v-model="queryParams.moveTwo"
          placeholder="请输入有无变动2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="有无变动3" prop="moveThree">
        <el-input
          v-model="queryParams.moveThree"
          placeholder="请输入有无变动3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="目前实习单位/待业地址" prop="currentAddress">
        <el-input
          v-model="queryParams.currentAddress"
          placeholder="请输入目前实习单位/待业地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位" prop="jobs">
        <el-input
          v-model="queryParams.jobs"
          placeholder="请输入岗位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前薪资" prop="currentSalary">
        <el-input
          v-model="queryParams.currentSalary"
          placeholder="请输入当前薪资"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否签订协议" prop="employmentAgreement">

        <el-radio-group v-model="queryParams.employmentAgreement">
          <el-radio label="1">是</el-radio>
          <el-radio label="2">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="推荐方式" prop="recommendWays">
        <el-input
          v-model="queryParams.recommendWays"
          placeholder="请输入推荐方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推荐老师" prop="recommendTeacher">
        <el-input
          v-model="queryParams.recommendTeacher"
          placeholder="请输入推荐老师"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否对口" prop="counterpart">
        <el-radio-group v-model="queryParams.counterpart">
          <el-radio label="1">是</el-radio>
          <el-radio label="2">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否核心对口" prop="coreCounterpart">
        <el-radio-group v-model="queryParams.coreCounterpart">
          <el-radio label="1">是</el-radio>
          <el-radio label="2">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="回访记录" prop="returnVisit">
        <el-input
          v-model="queryParams.returnVisit"
          placeholder="请输入回访记录"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['employment:employmentlist:add']"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['employment:employmentlist:edit']"
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['employment:employmentlist:remove']"
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['employment:employmentlist:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="employmentlistList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="就业id" align="center" prop="employmentId" />
      <el-table-column label="学生id" align="center" prop="studentId" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="初次报到时间" align="center" prop="firstInternshipDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.firstInternshipDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="初次报到单位" align="center" prop="firstInternshipCompany" />
      <el-table-column label="有无变动1" align="center" prop="moveOne" />
      <el-table-column label="有无变动2" align="center" prop="moveTwo" />
      <el-table-column label="有无变动3" align="center" prop="moveThree" />
      <el-table-column label="学员状态(未就业/在职/已离职/已跳槽)" align="center" prop="studentStatus" />
      <el-table-column label="目前实习单位/待业地址" align="center" prop="currentAddress" />
      <el-table-column label="岗位" align="center" prop="jobs" />
      <el-table-column label="当前薪资" align="center" prop="currentSalary" />
      <el-table-column label="是否签订协议" align="center" prop="employmentAgreement" :formatter="cellFormat" />
      <el-table-column label="推荐方式" align="center" prop="recommendWays" />
      <el-table-column label="推荐老师" align="center" prop="recommendTeacher" />
      <el-table-column label="是否对口" align="center" prop="counterpart" :formatter="cellFormat" />
      <el-table-column label="是否核心对口" align="center" prop="coreCounterpart" :formatter="cellFormat" />
      <el-table-column label="回访记录" align="center" prop="returnVisit" />
      <el-table-column label="就业照片" align="center" prop="jobPicture" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['employment:employmentlist:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            v-hasPermi="['employment:employmentlist:remove']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改就业列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="学生id" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学生id" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="初次报到时间" prop="firstInternshipDate">
          <el-date-picker
            v-model="form.firstInternshipDate"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择初次报到时间"
          />
        </el-form-item>
        <el-form-item label="初次报到单位" prop="firstInternshipCompany">
          <el-input v-model="form.firstInternshipCompany" placeholder="请输入初次报到单位" />
        </el-form-item>
        <el-form-item label="有无变动1" prop="moveOne">
          <el-input v-model="form.moveOne" placeholder="请输入有无变动1" />
        </el-form-item>
        <el-form-item label="有无变动2" prop="moveTwo">
          <el-input v-model="form.moveTwo" placeholder="请输入有无变动2" />
        </el-form-item>
        <el-form-item label="有无变动3" prop="moveThree">
          <el-input v-model="form.moveThree" placeholder="请输入有无变动3" />
        </el-form-item>
        <el-form-item label="目前实习单位/待业地址" prop="currentAddress">
          <el-input v-model="form.currentAddress" placeholder="请输入目前实习单位/待业地址" />
        </el-form-item>
        <el-form-item label="岗位" prop="jobs">
          <el-input v-model="form.jobs" placeholder="请输入岗位" />
        </el-form-item>
        <el-form-item label="当前薪资" prop="currentSalary">
          <el-input v-model="form.currentSalary" placeholder="请输入当前薪资" />
        </el-form-item>
        <el-form-item label="是否签订协议" prop="employmentAgreement">
          <el-radio-group v-model="form.employmentAgreement">
            <el-radio label="1">是</el-radio>
            <el-radio label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="学员状态(未就业/在职/已离职/已跳槽)" prop="studentStatus">
          <el-radio-group v-model="form.studentStatus">
            <el-radio label="未就业">未就业</el-radio>
            <el-radio label="在职">在职</el-radio>
            <el-radio label="已离职">已离职</el-radio>
            <el-radio label="已跳槽">已跳槽</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="推荐方式" prop="recommendWays">
          <el-input v-model="form.recommendWays" placeholder="请输入推荐方式" />
        </el-form-item>
        <el-form-item label="推荐老师" prop="recommendTeacher">
          <el-input v-model="form.recommendTeacher" placeholder="请输入推荐老师" />
        </el-form-item>
        <el-form-item label="是否对口" prop="counterpart">
          <el-radio-group v-model="form.counterpart">
            <el-radio label="1">是</el-radio>
            <el-radio label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否核心对口" prop="coreCounterpart">
          <el-radio-group v-model="form.coreCounterpart">
            <el-radio label="1">是</el-radio>
            <el-radio label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="回访记录" prop="returnVisit">
          <el-input v-model="form.returnVisit" placeholder="请输入回访记录" />
        </el-form-item>
        <el-form-item label="就业照片" prop="jobPicture">
          <el-input v-model="form.jobPicture" placeholder="请输入就业照片" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEmploymentlist, getEmploymentlist, delEmploymentlist, addEmploymentlist, updateEmploymentlist } from '@/api/employment/employmentlist'

export default {
  name: 'Employmentlist',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 就业列表表格数据
      employmentlistList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentId: null,
        name: null,
        firstInternshipDate: null,
        firstInternshipCompany: null,
        moveOne: null,
        moveTwo: null,
        moveThree: null,
        studentStatus: null,
        currentAddress: null,
        jobs: null,
        currentSalary: null,
        employmentAgreement: null,
        recommendWays: null,
        recommendTeacher: null,
        counterpart: null,
        coreCounterpart: null,
        returnVisit: null,
        jobPicture: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studentId: [
          { required: true, message: '学生id不能为空', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        firstInternshipDate: [
          { required: true, message: '初次报到时间不能为空', trigger: 'blur' }
        ],
        firstInternshipCompany: [
          { required: true, message: '初次报到单位不能为空', trigger: 'blur' }
        ],
        studentStatus: [
          { required: true, message: '学员状态(未就业/在职/已离职/已跳槽)不能为空', trigger: 'blur' }
        ],
        currentSalary: [
          { required: true, message: '当前薪资不能为空', trigger: 'blur' }
        ],
        employmentAgreement: [
          { required: true, message: '是否签订协议不能为空', trigger: 'blur' }
        ],
        recommendWays: [
          { required: true, message: '推荐方式不能为空', trigger: 'blur' }
        ],
        recommendTeacher: [
          { required: true, message: '推荐老师不能为空', trigger: 'blur' }
        ],
        counterpart: [
          { required: true, message: '是否对口不能为空', trigger: 'blur' }
        ],
        coreCounterpart: [
          { required: true, message: '是否核心对口不能为空', trigger: 'blur' }
        ],
        returnVisit: [
          { required: true, message: '回访记录不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    cellFormat(row, column, cellValue, index) {
      return cellValue === 1 ? '是' : '否'
    },
    /** 查询就业列表列表 */
    getList() {
      this.loading = true
      listEmploymentlist(this.queryParams).then(response => {
        this.employmentlistList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        employmentId: null,
        studentId: null,
        name: null,
        firstInternshipDate: null,
        firstInternshipCompany: null,
        moveOne: null,
        moveTwo: null,
        moveThree: null,
        studentStatus: '0',
        currentAddress: null,
        jobs: null,
        currentSalary: null,
        employmentAgreement: null,
        recommendWays: null,
        recommendTeacher: null,
        counterpart: null,
        coreCounterpart: null,
        returnVisit: null,
        jobPicture: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.employmentId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加就业列表'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const employmentId = row.employmentId || this.ids
      getEmploymentlist(employmentId).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改就业列表'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.employmentId != null) {
            updateEmploymentlist(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addEmploymentlist(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const employmentIds = row.employmentId || this.ids
      this.$modal.confirm('是否确认删除就业列表编号为"' + employmentIds + '"的数据项？').then(function() {
        return delEmploymentlist(employmentIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('employment/employmentlist/export', {
        ...this.queryParams
      }, `employmentlist_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
